//
//  SMSearchBar.m
//  YachtParty
//
//  Created by apple on 17/3/13.
//  Copyright © 2017年 spider. All rights reserved.
//

#import "SMSearchBar.h"
#ifdef ISVersion9
#define KNFont(s) [UIFont systemFontOfSize:s]
#else
#define KNFont(s) [UIFont fontWithName:@"PingFangSC-Regular" size:s]
//#define KNFont(s) [UIFont fontWithName:@"MicrosoftYaHei" size:s]
#endif

@interface SMSearchBar()

@property (strong, nonatomic)UIColor *backColor;
@property (strong, nonatomic)UIColor *textBackColor;
@property (strong, nonatomic)UIColor *fontColor;

@end

@implementation SMSearchBar

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    if(!self.backColor){
        self.backColor = [UIColor whiteColor];
    }
    
    if(!self.textBackColor){
        self.textBackColor = [UIColor whiteColor];
    }
    
    if(!self.fontColor){
        self.fontColor = [UIColor blackColor];
    }
    
    self.searchBarStyle = UISearchBarStyleMinimal;
    [self setBackgroundColor:self.backColor];
    self.barTintColor = self.backColor;
    [self.layer setBackgroundColor:self.backColor.CGColor];
    [self.layer setCornerRadius:15];
    self.layer.masksToBounds = YES;
    for (UIView *view in self.subviews)
    {
        if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
            for (UIView *subview in view.subviews) {
                if ([subview isKindOfClass:NSClassFromString(@"UITextField")]) {
                    UITextField *textField = (UITextField *)subview;
                    //textField.frame = self.bounds;
                    textField.font = KNFont(14);
                    textField.textColor = self.fontColor;
                    textField.borderStyle = UITextBorderStyleNone;
                    [textField setBackgroundColor:self.textBackColor];
                    break;
                }
            }
            break;
        }
    }
}

- (void)setBackgroundColor:(UIColor *)backgroundColor textFieldBackgroundColor:(UIColor   *)textFieldBackgroundColor fontColor:(UIColor *)fontColor{
    
    self.backColor = backgroundColor;
    self.textBackColor = textFieldBackgroundColor;
    self.fontColor = fontColor;
    //重新刷新界面
    [self setNeedsDisplay];
    
}

@end
